package com.kinghood.productcenter.controller.base;

import com.kinghood.infrastructure.api.authority.SysLogModuleEnum;
import com.kinghood.infrastructure.aspect.OperatorLog;
import com.kinghood.infrastructure.model.KingHoodResponseVO;
import com.kinghood.productcenter.common.model.dto.MoveChangeSortReqDTO;
import com.kinghood.infrastructure.model.dto.StatusReqDTO;
import com.kinghood.productcenter.common.model.dto.base.CategoryQueryDTO;
import com.kinghood.productcenter.common.model.dto.base.CategoryReqDTO;
import com.kinghood.productcenter.service.base.IBaseCategoryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * <p>
 * 基础选项-品类 前端控制器
 * </p>
 *
 * @author KingHood
 * @since 2023-12-20
 */
@RestController
@RequestMapping("/baseCategory")
public class BaseCategoryController {
    @Resource
    private IBaseCategoryService categoryService;

    @PostMapping("/listAllCategory")
    public KingHoodResponseVO listAllCategory(@Valid @RequestBody CategoryQueryDTO param) {
        return KingHoodResponseVO.success(categoryService.listAllCategory(param));
    }

    /**
     * 新增更新
     *
     * @param param
     * @author jp
     * @date 2023/12/21
     */
    @OperatorLog(module = SysLogModuleEnum.Type.PRODUCT_CATEGORY,content = "品类管理-新增、修改品类")
    @PostMapping("/addOrUpdateCategory")
    public KingHoodResponseVO addOrUpdateCategory(@Valid @RequestBody CategoryReqDTO param) {
        categoryService.addOrUpdateCategory(param);
        return KingHoodResponseVO.success();
    }

    /**
     * 更新状态
     *
     * @param param 参数
     * @author jp
     * @date 2023/12/21
     */
    @OperatorLog(module = SysLogModuleEnum.Type.PRODUCT_CATEGORY,content = "品类管理-修改状态")
    @PostMapping("/updateCategoryStatus")
    public KingHoodResponseVO updateCategoryStatus(@Valid @RequestBody StatusReqDTO param) {
        categoryService.updateCategoryStatus(param);
        return KingHoodResponseVO.success();
    }

    /**
     * 详细
     *
     * @param id id
     * @author jp
     * @date 2023/12/28
     */
    @GetMapping(value = "/detailCategory/{id}")
    public KingHoodResponseVO detailCategory(@PathVariable("id") Long id){
        return KingHoodResponseVO.success(categoryService.detailCategory(id));
    }

    /**
     * 根据id删除
     *
     * @param id id
     * @author jp
     * @date 2023/12/21
     */
    @OperatorLog(module = SysLogModuleEnum.Type.PRODUCT_CATEGORY,content = "品类管理-删除品类")
    @RequestMapping("/delCategory/{id}")
    public KingHoodResponseVO delCategory(@PathVariable("id") Long id) {
        categoryService.delCategory(id);
        return KingHoodResponseVO.success();
    }

    /**
     * 拖动更改排序
     *
     * @param param 参数
     * @author jp
     * @date 2023/12/27
     */
    @OperatorLog(module = SysLogModuleEnum.Type.PRODUCT_CATEGORY,content = "品类管理-修改排序")
    @PostMapping("/changeSort")
    public KingHoodResponseVO changeSort(@Valid @RequestBody MoveChangeSortReqDTO param) {
        categoryService.changeSort(param);
        return KingHoodResponseVO.success();
    }

    /**
     * 下载品类
     *
     * @param param 参数
     * @author jp
     * @date 2024/01/04
     */
    @PostMapping("/downloadCategory")
    public void downloadCategory(@RequestBody CategoryQueryDTO param, HttpServletResponse response) {
        categoryService.downloadCategory(param, response);
    }
}
